#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    bool isAnagram(string s, string t) {
        multiset<char> ms;
        multiset<char> mt;
        for (auto e : s)
            ms.insert(e);
        for (auto e : t)
            mt.insert(e);
        if (ms.size() != mt.size())
            return false;
        auto begin1 = ms.begin();
        auto begin2 = mt.begin();
        while (begin1 != ms.end())
        {
            if (*begin1 != *begin2)
                return false;
            begin1++;
            begin2++;
        }
        return true;
    }
};

class Solution {
public:
    bool isAnagram(string s, string t) {
        int hash[26] = { 0 };
        for (auto e : s)
            hash[e - 'a']++;
        for (auto e : t)
            hash[e - 'a']--;
        for (int i = 0; i < 26; i++)
        {
            if (hash[i] != 0)
                return false;
        }
        return true;
    }
};

class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        vector<int> ret;
        unordered_set<int> s1;
        unordered_set<int> s2;
        unordered_map<int, int> m;

        for (auto& e : nums1)
            s1.insert(e);
        for (auto& e : nums2)
            s2.insert(e);

        for (auto& e : s1)
            m[e]++;
        for (auto& e : s2)
            m[e]++;
        for (auto& e : m)
        {
            if (e.second == 2)
                ret.push_back(e.first);
        }
        return ret;
    }
};

class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        unordered_set<int> ret_set;
        unordered_set<int> num_set(nums1.begin(), nums1.end());
        for (auto e : nums2)
        {
            if (num_set.find(e) != num_set.end())
                ret_set.insert(e);
        }
        vector<int> ret(ret_set.begin(), ret_set.end());
        return ret;
    }
};

class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        unordered_set<int> ret_set;
        int hash[1001] = { 0 };
        for (auto e : nums1)
            hash[e] = 1;
        for (auto e : nums2)
        {
            if (hash[e] == 1)
                ret_set.insert(e);
        }
        vector<int> ret(ret_set.begin(), ret_set.end());
        return ret;
    }
};

class Solution {
public:
    bool isHappy(int n) {
        unordered_set<int> us;
        us.insert(n);
        while (n != 1)
        {
            int sum = 0;
            while (n)
            {
                sum += (n % 10) * (n % 10);
                n /= 10;
            }
            n = sum;
            if (us.find(n) == us.end())
                us.insert(n);
            else
                return false;
        }
        return true;
    }
};

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        for (int i = 0; i < nums.size(); i++)
        {
            for (int j = i + 1; j < nums.size(); j++)
            {
                if (nums[i] + nums[j] == target)
                    return { i,j };
            }
        }
        return {};
    }
};

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> um;
        int num = 0;
        for (auto e : nums)
        {
            if (um.find(target - e) == um.end())
                um.insert(make_pair(e, num++));
            else
                return { um.find(target - e)->second,num++ };
        }
        return {};
    }
};